package com.commerce.model;

import lombok.Data;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
public class AD {

    private int id;
    private String remark;//备注
    private String imgurl;//图片路径
    private boolean open;//开启或关闭
    private int order;//排序
    private Date valid_start_time;//有效开始时间
    private Date valid_end_time;//有效结束时间
    private Date create_time;//创建时间


    public void setTime_range(String time_range){
        if(time_range != null && !time_range.trim().equals("")){
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String[] times = time_range.split(" - ");
            try {
                valid_start_time = dateFormat.parse(times[0].trim()+" 00:00:00");
                valid_end_time = dateFormat.parse(times[1].trim()+" 23:59:59");
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    }
}
